package com.hackathon.chgk.activities;

import com.hackathon.chgk.R;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;

public class Preferences extends PreferenceActivity {
    private ListPreference modeListPref;
    SharedPreferences gameSettings;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.layout.preferences);
            // Get the custom preference
            modeListPref = (ListPreference)findPreference("mode_list_pref");
            modeListPref.setTitle(modeListPref.getValue());

			SharedPreferences gameSettings = getSharedPreferences("mode_list_pref", MODE_PRIVATE);
			SharedPreferences.Editor prefEditor = gameSettings.edit();
			prefEditor.putString("mode_list_pref", modeListPref.getValue().toString());
			prefEditor.commit();
	        
            modeListPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
				public boolean onPreferenceChange(Preference preference, Object newValue) {
					modeListPref.setTitle(newValue.toString());
					SharedPreferences gameSettings = getSharedPreferences("mode_list_pref", MODE_PRIVATE);
					SharedPreferences.Editor prefEditor = gameSettings.edit();
					prefEditor.putString("mode_list_pref", newValue.toString());
					prefEditor.commit();
					return true;
				}
			});
    }
    
}
